package com.cxria.script

import okhttp3.OkHttpClient
import okhttp3.Request

@Singleton(lazy = true)
class OkHttpUtils {

    def client = new OkHttpClient()

    InputStream get(String url){
        def request = new Request.Builder()
                .url(url)
                .build()
        def response = client.newCall(request).execute()
        response.body().byteStream()
    }

    InputStream get(String url, long start, long end){
        def request = new Request.Builder()
                .url(url)
                .addHeader("range", "bytes=" + start + "-" + end)
                .build()
        def response = client.newCall(request).execute()
        response.body().byteStream()
    }

}
